import java.util.*;

public class code1{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int ret = (int)1e9;

        for(char i='a';i<='z';i++) {
            int sum = 0;
            for(int j=0;j<s.length;j++) {
                sum += Math.min(Math.abs(s[j]-i),26-Math.abs(s[j]-i));
            }
            ret = Math.min(ret,sum);
        }
        System.out.println(ret);
    }
}